:root {
    --primary: #1769d2;
    --primary-dark: #1059b7;
    --body-bg: #f5f6f8;
    --border: #dfe3e8;
    --text: #212529;
    --muted: #6c757d;
    --sidebar-width: 246px;
    --topbar-height: 58px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
    margin: 0;
    background: var(--body-bg);
    color: var(--text);
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 14px;
}
a { text-decoration: none; }
.app-shell { min-height: 100vh; }
.sidebar {
    position: fixed;
    z-index: 1040;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: #fff;
    border-right: 1px solid var(--border);
}
.sidebar-brand {
    height: 72px;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    color: #1d2733;
}
.sidebar-brand strong { display: block; font-size: 17px; font-weight: 600; line-height: 1.1; }
.sidebar-brand small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.brand-mark {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--primary);
    border-radius: 3px;
    font-size: 20px;
}
.sidebar-nav { padding: 14px 10px; flex: 1; overflow-y: auto; }
.sidebar-link {
    height: 41px;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 12px;
    margin-bottom: 3px;
    color: #3b4652;
    border-radius: 3px;
    font-size: 13.5px;
}
.sidebar-link i { width: 18px; text-align: center; font-size: 15px; }
.sidebar-link:hover { background: #f1f3f5; color: #1e2935; }
.sidebar-link.active { background: var(--primary); color: #fff; }
.sidebar-footer { padding: 15px 20px; color: var(--muted); border-top: 1px solid var(--border); font-size: 12px; }
.status-dot { width: 7px; height: 7px; display: inline-block; margin-right: 6px; background: #198754; border-radius: 50%; }
.main-column { min-height: 100vh; margin-left: var(--sidebar-width); display: flex; flex-direction: column; }
.topbar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 22px;
    background: #fff;
    border-bottom: 1px solid var(--border);
}
.topbar-menu { display: none; width: 36px; height: 36px; border: 1px solid var(--border); background: #fff; border-radius: 3px; font-size: 20px; }
.topbar-context { color: var(--muted); font-size: 13px; }
.user-menu { display: flex; align-items: center; gap: 9px; padding: 6px 8px; background: transparent; border: 0; color: var(--text); }
.user-avatar { width: 31px; height: 31px; display: grid; place-items: center; background: #eef3f9; border: 1px solid #d7e1ee; color: var(--primary); border-radius: 3px; }
.user-copy { min-width: 90px; text-align: left; line-height: 1.05; }
.user-copy strong { display: block; font-size: 13px; font-weight: 600; }
.user-copy small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.content-area { width: 100%; max-width: 1680px; flex: 1; padding: 22px 24px; }
.app-footer { display: flex; justify-content: space-between; padding: 13px 24px; color: #7a828a; background: #fff; border-top: 1px solid var(--border); font-size: 11px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 17px; }
.page-title { margin: 0; font-size: 25px; font-weight: 600; letter-spacing: -.2px; }
.page-description { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.page-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.panel { margin-bottom: 17px; background: #fff; border: 1px solid var(--border); border-radius: 4px; }
.panel-header { min-height: 45px; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.panel-title { margin: 0; font-size: 15px; font-weight: 600; }
.panel-body { padding: 16px; }
.panel-footer { padding: 12px 16px; background: #fafbfc; border-top: 1px solid var(--border); }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 17px; }
.summary-box { min-height: 90px; display: flex; align-items: center; gap: 14px; padding: 15px 17px; background: #fff; border: 1px solid var(--border); border-radius: 4px; }
.summary-icon { width: 43px; height: 43px; display: grid; place-items: center; flex: 0 0 auto; background: #eef4fc; border: 1px solid #dbe8f8; border-radius: 3px; color: var(--primary); font-size: 19px; }
.summary-box.success .summary-icon { color: #198754; background: #edf7f2; border-color: #d8eee3; }
.summary-box.danger .summary-icon { color: #dc3545; background: #fbefef; border-color: #f3dada; }
.summary-box.warning .summary-icon { color: #b76a00; background: #fff7e7; border-color: #f5e6c6; }
.summary-label { color: var(--muted); font-size: 12px; }
.summary-value { margin-top: 2px; color: #1c2733; font-size: 24px; font-weight: 600; line-height: 1; }
.btn { --bs-btn-border-radius: 3px; font-size: 13px; }
.btn-sm { --bs-btn-padding-y: .31rem; --bs-btn-padding-x: .62rem; }
.btn-primary { --bs-btn-bg: var(--primary); --bs-btn-border-color: var(--primary); --bs-btn-hover-bg: var(--primary-dark); --bs-btn-hover-border-color: var(--primary-dark); }
.form-label { margin-bottom: 5px; color: #343a40; font-size: 13px; font-weight: 500; }
.form-control, .form-select { min-height: 38px; border-color: #cfd5db; border-radius: 3px; font-size: 13px; }
.form-control:focus, .form-select:focus { border-color: #6ba3e8; box-shadow: 0 0 0 .16rem rgba(23,105,210,.12); }
.form-text { color: #77808a; font-size: 11px; }
.filter-bar { padding: 14px 15px 9px; background: #fff; border: 1px solid var(--border); border-radius: 4px; margin-bottom: 14px; }
.filter-bar .form-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .2px; }
.table { --bs-table-hover-bg: #f7f9fb; margin-bottom: 0; font-size: 13px; }
.table > :not(caption) > * > * { padding: .65rem .7rem; border-bottom-color: #e5e8eb; vertical-align: middle; }
.table thead th { background: #f5f7f9; color: #47515c; border-bottom: 1px solid #d6dbe0; font-size: 11.5px; font-weight: 600; text-transform: uppercase; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-link { color: #155fb9; font-weight: 500; }
.text-truncate-cell { max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-badge { display: inline-block; padding: 3px 6px; border-radius: 3px; color: #fff; font-size: 11px; font-weight: 600; line-height: 1.2; }
.status-success { background: #198754; }
.status-danger { background: #dc3545; }
.status-warning { background: #dc8800; }
.status-secondary { background: #6c757d; }
.pagination { --bs-pagination-border-radius: 2px; --bs-pagination-font-size: 12px; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty-state i { display: block; margin-bottom: 8px; color: #aeb6bf; font-size: 30px; }
.empty-state strong { display: block; margin-bottom: 4px; color: #49515a; }
.qr-preview-box { min-height: 270px; display: flex; align-items: center; justify-content: center; padding: 16px; background: #fff; border: 1px dashed #bfc6cd; }
.qr-preview-box img, .qr-preview-box canvas { max-width: 100%; height: auto; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef1f4; }
.login-card { width: 100%; max-width: 410px; background: #fff; border: 1px solid #d9dee3; border-radius: 4px; }
.login-header { padding: 24px 28px 19px; border-bottom: 1px solid var(--border); text-align: center; }
.login-logo { width: 48px; height: 48px; display: grid; place-items: center; margin: 0 auto 12px; background: var(--primary); color: #fff; border-radius: 3px; font-size: 25px; }
.login-title { margin: 0; font-size: 20px; font-weight: 600; }
.login-subtitle { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.login-body { padding: 23px 28px 27px; }
.setup-shell { width: 100%; max-width: 820px; margin: 35px auto; }
.setup-steps { display: flex; margin-bottom: 18px; border: 1px solid var(--border); background: #fff; }
.setup-step { flex: 1; padding: 11px 13px; color: var(--muted); border-right: 1px solid var(--border); font-size: 12px; }
.setup-step:last-child { border-right: 0; }
.setup-step.active { color: #fff; background: var(--primary); }
.setup-check { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #edf0f2; }
.setup-check:last-child { border-bottom: 0; }
.chart-wrap { position: relative; min-height: 260px; }
.metric-note { color: var(--muted); font-size: 11px; }
.code-text { font-family: Consolas, Monaco, monospace; font-size: 12px; }
.qr-style-grid { display: grid; grid-template-columns: repeat(5, minmax(118px, 1fr)); gap: 9px; }
.qr-style-option { position: relative; min-width: 0; }
.qr-style-option input { position: absolute; opacity: 0; pointer-events: none; }
.qr-style-label { min-height: 142px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; padding: 9px 7px; border: 1px solid #cfd5db; border-radius: 3px; background: #fff; cursor: pointer; text-align: center; }
.qr-style-label:hover { background: #f7f9fb; border-color: #9eb9da; }
.qr-style-option input:checked + .qr-style-label { border: 2px solid var(--primary); padding: 8px 6px; background: #f4f8fd; }
.qr-style-option input:focus-visible + .qr-style-label { outline: 2px solid #8bb5e8; outline-offset: 2px; }
.qr-style-preview { width: 78px; height: 78px; overflow: hidden; }
.qr-style-preview canvas, .qr-style-preview svg { width: 78px !important; height: 78px !important; display: block; }
.qr-style-name { color: #27313b; font-size: 12px; font-weight: 600; }
.qr-style-desc { color: var(--muted); font-size: 10px; line-height: 1.2; }
.assignment-note { padding: 11px 13px; border-left: 3px solid #d68a00; background: #fff8e8; color: #614b22; font-size: 12px; }
.batch-code { padding: 3px 6px; background: #edf1f5; border: 1px solid #dce1e6; border-radius: 2px; font-family: Consolas, Monaco, monospace; font-size: 11px; }
.print-preview-panel { position: sticky; top: 14px; }
.print-preview-stage { min-height: 620px; display: grid; place-items: center; padding: 22px; overflow: auto; background: #e8ebef; }
.print-paper { position: relative; width: min(100%, 520px); aspect-ratio: 210 / 297; flex: 0 0 auto; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.15); overflow: hidden; }
.print-paper.landscape { width: min(100%, 720px); aspect-ratio: 297 / 210; }
.print-label-preview { position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px; overflow: hidden; border-style: solid; border-color: #252525; color: #111; background: #fff; text-align: center; }
.print-label-preview strong { flex: 0 0 auto; max-width: 100%; overflow: hidden; font-size: clamp(6px, .85vw, 11px); line-height: 1.05; text-overflow: ellipsis; white-space: nowrap; }
.print-label-preview small { display: block; flex: 0 0 auto; max-width: 100%; overflow: hidden; font-size: clamp(4px, .55vw, 7px); line-height: 1.05; text-overflow: ellipsis; white-space: nowrap; }
.print-qr-mini { min-height: 0; display: grid; place-items: center; flex: 1; aspect-ratio: 1; overflow: hidden; }
.print-qr-mini canvas, .print-qr-mini svg { width: 100% !important; height: 100% !important; display: block; }
.print-preview-error { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; padding: 30px; color: #9d5d00; background: #fff8e8; text-align: center; }
.print-preview-error i { font-size: 30px; }
.nav-tabs { --bs-nav-tabs-border-radius: 3px; }
.nav-tabs .nav-link { color: #4d5965; font-size: 13px; }
.modal-content, .dropdown-menu, .alert { border-radius: 4px; }
.sidebar-backdrop { display: none; }

@media (max-width: 1100px) {
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .qr-style-grid { grid-template-columns: repeat(3, minmax(118px, 1fr)); }
}
@media (max-width: 820px) {
    .sidebar { transform: translateX(-100%); transition: transform .18s ease; }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop.show { position: fixed; z-index: 1030; inset: 0; display: block; background: rgba(20,30,40,.35); }
    .main-column { margin-left: 0; }
    .topbar-menu { display: grid; place-items: center; margin-right: 12px; }
    .content-area { padding: 18px 15px; }
    .page-header { align-items: stretch; flex-direction: column; }
    .page-actions { justify-content: flex-start; }
    .print-preview-panel { position: static; }
    .print-preview-stage { min-height: 460px; padding: 12px; }
}
@media (max-width: 560px) {
    .summary-grid { grid-template-columns: 1fr; }
    .user-copy, .topbar-context { display: none; }
    .setup-shell { margin: 15px auto; }
    .setup-steps { display: none; }
    .login-body, .login-header { padding-left: 20px; padding-right: 20px; }
    .qr-style-grid { grid-template-columns: repeat(2, minmax(118px, 1fr)); }
}
